package com.study.talk.data.repository

import android.util.Log
import com.study.talk.data.model.UserInfo
import com.study.talk.data.model.vo.GroupUserInfoVo
import com.study.talk.data.remote.FriendApi
import javax.inject.Inject

class FriendRepository @Inject constructor(private val friendApi: FriendApi) : BaseRepository() {

    companion object {
        private const val TAG = "FriendRepository"
    }

    suspend fun getFriends(): List<UserInfo> {
        val response = friendApi.getFriends()
        if (response.isSuccessful) {
            if (response.body()?.status == 200) {
                if (response.body()?.data == null) {
                    Log.e(TAG, "getFriends: response.body()?.data is null")
                    return listOf()
                } else {
                    return response.body()?.data!!
                }
            } else {
                Log.e(TAG, "getFriends: error,msg:${response.body()?.message}")
                return listOf()
            }
        } else {
            Log.e(TAG, "getFriends: request fail,msg:${response.message()}")
            return listOf()
        }
    }

    suspend fun friendNotInGroup(groupId: Int, userId: Int): List<UserInfo> {
        val response = friendApi.friendNotInGroup(
            GroupUserInfoVo(
                groupId,
                userId
            )
        )
        if (response.isSuccessful) {
            if (response.body()?.status == 200) {
                if (response.body()?.data == null) {
                    Log.e(TAG, "friendNotInGroup: response.body()?.data is null")
                    return listOf()
                } else {
                    return response.body()?.data!!
                }
            } else {
                Log.e(TAG, "friendNotInGroup: error,msg:${response.body()?.message}")
                return listOf()
            }
        } else {
            Log.e(TAG, "friendNotInGroup: request fail,msg:${response.message()}")
            return listOf()
        }
    }
}